package YPTServerRegister

import (
	"reflect"
	"crypto/md5"
	"strconv"
	"time"
	"encoding/hex"
	"math/rand"
)

func simpleEtcdBalancer(etcdPoints []string) string{
	return etcdPoints[getRandomArrayIndex(len(etcdPoints))]
}

func choosenAddress(addr []Address) Address{
	return addr[getRandomArrayIndex(len(addr))]
}

func getRandomArrayIndex(length int) int{
	rand.Seed(time.Now().Unix())
	return int(rand.Float32() * float32(length))
}

func get32Z()string{ //etcd range操作中使用32个Z表示右区间,TODO 目前没找到其他方法
	s := ""
	for i:=0;i<32;i++{
		s += "z"
	}
	return s
}

func StructEmpty(a,b interface{})  bool{
	return reflect.DeepEqual(a,b)
}

func getRandomMD5String() string{ //取一个随机的MD5值用于区分每个服务
	m := md5.New()
	m.Write([]byte(strconv.FormatInt(time.Now().Unix(),10)))
	return hex.EncodeToString(m.Sum(nil))
}
